package org.logan.sample.web.base.shiro;

import org.apache.shiro.cache.AbstractCacheManager;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.MapCache;
import org.apache.shiro.util.SoftHashMap;
import org.logan.sample.web.main.service.common.SysConfigs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Desc：
 * 
 * @Title：RedisCacheManager
 * @author: Logan
 * @version: 1.0
 * @date: 2016年11月28日 下午2:39:32
 */
public class ShiroSCacheManager extends AbstractCacheManager {
	private static final Logger logger = LoggerFactory.getLogger(ShiroSCacheManager.class);

	@Autowired
	SysConfigs sysConfigs;

	@Override
	protected Cache createCache(String name) throws CacheException {
		logger.debug("Shiro创建缓存："+name);
		if (sysConfigs.getSysEnableItems().get("redis")) {
			return new RedisCache<String, Object>(name);
		} else {
			return new MapCache<Object, Object>(name, new SoftHashMap<Object, Object>());
		}
	}

}
